﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;

namespace ScheduleMaker.DB.CoreDAO
{
    public class GroupDAO : CoreAbstractDAO<Group>
    {
        private AdapterAbstractDAO<Group, GroupSchool> wrappedAbstractDAOSchool;
        private GroupDAOSchool wrappedDAOSchool;

        public GroupDAO(GroupDAOSchool wrappedDAOSchool)
        {
            this.wrappedDAOSchool = wrappedDAOSchool;
            this.wrappedAbstractDAOSchool =
                new AdapterAbstractDAO<Group, GroupSchool>((AbstractDAO<GroupSchool>)wrappedDAOSchool);
        }

        public override void update(Group entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.update(entity);
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }
        }

        public override void save(Group entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.save(entity);
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }
        }

        public override void saveOrUpdate(Group entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.saveOrUpdate(entity);
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }
        }

        public override void delete(Group entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.delete(entity);
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }
        }

        public override Group getById(int id)
        {
            Group entity;
            if (wrappedDAOSchool != null)
            {
                entity = wrappedAbstractDAOSchool.getById(id);
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }

            return entity;
        }

        public override IList<Group> getAll()
        {
            IList<Group> records;
            if (wrappedDAOSchool != null)
            {
                records = wrappedAbstractDAOSchool.getAll();
            }
            else
            {
                throw new NotImplementedException("GroupDAOSchool isn't initialized");
            }

            return records;
        }
    }
}
